package com.lwx.smipleemps.dao;

import com.lwx.smipleemps.common.domain.Admin;
import com.lwx.smipleemps.common.utils.HibernateUtils;
import org.hibernate.Query;
import org.hibernate.Session;

public class AdminDaoImpl implements AdminDao {
    //输入数据库需要的
 /*   Session session;*/

    public AdminDaoImpl() {
        //只执行一次！！！！
        //this.session = HibernateUtils.getSession();
    }

    @Override
    public Admin selectAdminByName(String name) {
        String hql = " from Admin admin where admin.name = ? ";
        Query query = HibernateUtils.getSession().createQuery(hql);
        query.setString(0,name);
        return (Admin) query.uniqueResult();
    }

    @Override
    public Admin selectAdminById(Integer id) {
        return (Admin) HibernateUtils.getSession().get(Admin.class,id);
    }

    @Override
    public void updateAdmin(Admin admin) {

        HibernateUtils.getSession().update(admin);

    }
}
